#include <bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define ld long double
#define lala for(ll i=0;i<n;i++)
#define si set <int>
#define vi vector <int>
#define pii pair <int, int>
#define vpi vector <pii>
#define vpp vector <pair<int, pii>>
#define mii map <int, int>
#define mpi map <pii, int>
#define spi set <pii>
using namespace std;
const int MOD = 1e9 + 7;
ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void vin( vector<int> &v , int n ){for (int i = 0; i < n; i++){int x ;cin >> x; v.push_back(x);}}
void vout(vector<int> &v){for (int i = 0; i < v.size(); i++){cout << v[i] << " " ;}cout << endl;}
long long lcm(int a, int b){ return (a / gcd(a, b)) * b;}
int digits_count(int n){int d=0;while(n != 0){d++;n /=10;}return d;}
void hello()
{
int n;
cin>>n;
if(n==1)
{
vi a;
vin(a,6);
sort(a.begin(),a.end());
int j=1;
// vout(a);
for(auto i:a)
{
// cout<<i<<endl;
if(i==0)
continue;
else if(j!=i)
{
cout<<j-1<<endl;
return ;
}
j++;
}
cout<<j-1<<endl;
}
else if(n==2)
{
vi a,b;
vin(a,6);
vin(b,6);
// vin(c,6);
set<int>s;
for(auto i:a)
{
for(auto j:b)
{
s.insert(i);
s.insert(j);
s.insert(i*10+j);
s.insert(j*10+i);
}
}
int j=1;
for(auto i:s)
{
if(i==0)
continue;
else if(j!=i)
{
cout<<j-1<<endl;
return ;
}
j++;
}
cout<<j-1<<endl;
}
else
{
vi a,b,c;
vin(a,6);
vin(b,6);
vin(c,6);
set<int>s;
for(auto i:a)
{
for(auto j:b)
{
for(auto k:c)
{
s.insert(i);
s.insert(j);
s.insert(k);
s.insert(i*10+j);
s.insert(j*10+i);
s.insert(i*10+k);
s.insert(k*10+i);
s.insert(j*10+k);
s.insert(k*10+j);
}
}
}
int j=1;
for(auto i:s)
{
if(i==0)
continue;
if(j!=i)
{
cout<<j-1<<endl;
return ;
}
j++;
}
cout<<j-1<<endl;
}
}
int32_t main()
{
int t=1;
// cin>>t;
while(t--)
{
hello();
}
}
1546B - AquaMoon and Stolen String | 1353C - Board Moves |
902A - Visiting a Friend | 299B - Ksusha the Squirrel |
1647D - Madoka and the Best School in Russia | 1208A - XORinacci |
1539B - Love Song | 22B - Bargaining Table |
1490B - Balanced Remainders | 264A - Escape from Stones |
1506A - Strange Table | 456A - Laptops |
855B - Marvolo Gaunt's Ring | 1454A - Special Permutation |
1359A - Berland Poker | 459A - Pashmak and Garden |
1327B - Princesses and Princes | 1450F - The Struggling Contestant |
1399B - Gifts Fixing | 1138A - Sushi for Two |
982C - Cut 'em all | 931A - Friends Meeting |
1594A - Consecutive Sum Riddle | 1466A - Bovine Dilemma |
454A - Little Pony and Crystal Mine | 2A - Winner |
1622B - Berland Music | 1139B - Chocolates |
1371A - Magical Sticks | 1253A - Single Push |